home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / RUBBER.ZIP / RUBBER.DOC < prev    next >
Encoding:
Text File  |  1996-11-10  |  2.8 KB  |  60 lines

  1. Documentation for RUBBER
  2. Copyright (c) 1996 David Bollinger
  3. 103057.1460@compuserve.com
  4.  
  5. My $.02 on the topic of image warping:
  6.    (I assume we all know what x's and y's and u's and v's are?)
  7.    It all boils down to finding some way to convert between source and
  8. destination coordinates.  If you have a screen image measured with x's and
  9. y's and a texture image measured with u's and v's, then the question is simply
  10. "How do you convert an x to a u?"  Or vice versa.  Or y to v, or vice versa.
  11.  
  12.    Well, all you need is an equation.  Here's one:
  13.  
  14.    u = x
  15.    v = y
  16.  
  17.    That will basically just do a straight copy of the image.  For every pixel
  18. on the destination, the same pixel on the source will be read to provide the
  19. color.
  20.    Hm, but that's not very exciting, is it?  How about this one:
  21.  
  22.    u = a + b*Y + c*X + d*Y*Y + e*X*Y + f*X*X
  23.    v = g + h*Y + i*X + j*Y*Y + k*X*Y + l*X*X
  24.  
  25.    a and g are the intercepts, and b-f,h-l are the coefficients.  If you're
  26. after a specific effect you can think about what each value does (a and g
  27. are simple translation, c and h will scale linearly in X/Y respectively,
  28. others will rotate, skew and otherwise mess with it...) although I won't
  29. attempt to figure it all out for you.  ;>
  30.    The important point, though, is that you can use whatever equation you
  31. want.  You can leave out terms if they're not used to increase speed, you
  32. can use higher order polys, toss in some trig functions -- whatever you need
  33. to get the job done.  There's nothing special about the one listed above,
  34. other than it's the one used in the source code.  It's complex enough to be
  35. fun, but not too complex to be impossible to figure out.
  36.  
  37. The source code:
  38.    OK, so it's not fast - it uses floating point math liberally.  The
  39. purpose here isn't to show you how to optimize code, but to explain the
  40. technique.  I did rearrange the equation a little in the source code to
  41. improve performance, but it is the same one presented above.
  42.  
  43. So what's the practical value?
  44.    Well you could flood the scene with image warping demos. <g>  Or you can
  45. animate your textures - flowing lava, wavy water, hm, sound familiar?  <bg>
  46.    The demo values in RUBBER give you a hint as to what is possible, but BY
  47. NO MEANS come even close to exhausting the possibilities of this single
  48. equation.  Obviously, you can get cool animated warping effects too - just
  49. start with a set of coefficients that you like and modify them by slight
  50. amounts within a loop, that's what happens in RUBBERA - a very tame example
  51. of ONE of the types of animation you might achieve.
  52.  
  53. Want more info?
  54.    All of this is well-known stuff, you just gotta know where to look for
  55. it.  Good library search topics might include Digital Image Processing and
  56. G.I.S. (Geographic Information Systems - especially Photo Rectification).
  57.  
  58. That's all,
  59. Dave
  60.